from django.db import models
from django.utils.safestring import mark_safe

class Metatag(models.Model):
    url = models.URLField(help_text='The URL of the page to place the metatags')
    title = models.CharField(max_length=255, blank=True, null=True,
            help_text='The title of the page. Will be placed in the <title> tag if it exists.')
    keywords = models.TextField(blank=True, null=True,
            help_text='A comma separated list of keywords for the page. \
                        Will be placed in the <meta> keywords tag if they exist')
    description = models.TextField(null=True, blank=True,
            help_text='The full text description of the page.')
    extra = models.TextField(null=True, blank=True,
            help_text = 'Any extra HTML information that would go in the <head> section')
    
    def __unicode__(self):
        return self.url
        
    def tags(self):
        tags = ''
        if self.title:
            tags += '<title>%s</title>'%self.title
        if self.keywords:
            tags += '<meta name="keywords" content="%s"/>'%self.keywords
        if self.description:
            tags += '<meta name="description" content="%s"/>'%self.description
        if self.extra:
            tags += self.extra
        return mark_safe(tags)
        